﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Js1
{
    public partial class Form3 : Form
    {
        string s2;
        DBHelper db = new DBHelper();
        DataSet ds = new DataSet();
        SqlDataAdapter adapter;
        public Form3()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            db.OpenConnection();
            string str = "select count,teamName as hostTeamId,name as awayTeamId,competitionTime,competitionPosition,score,entryPerson,entryTime from ScheduleInfo  " +
                "inner join TeamInfo on TeamInfo.id=ScheduleInfo.hostTeamId " +
                "inner join ad on ad.id=ScheduleInfo.awayTeamId";
            adapter = new SqlDataAdapter(str,db.Connection);
            adapter.Fill(ds, "ScheduleInfo");
            this.dataGridView1.DataSource = ds.Tables["ScheduleInfo"];
          
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text.Trim().Equals(string.Empty))
            {
                MessageBox.Show("请输入搜索内容！");
                return;
            }
            db.OpenConnection();
            s2 = "select count,teamName as hostTeamId,name as awayTeamId,competitionTime,competitionPosition,score,entryPerson,entryTime from ScheduleInfo  inner join TeamInfo on TeamInfo.id=ScheduleInfo.hostTeamId " +
                "inner join ad on ad.id=ScheduleInfo.awayTeamId  where teamName like '"+textBox1.Text+"%'";
            SqlCommand comm = new SqlCommand(s2, db.Connection);
            SqlDataReader read = comm.ExecuteReader();

            if (!read.HasRows)
            {

                MessageBox.Show("目前还没有改赛事！", "错误提示框", MessageBoxButtons.OK, MessageBoxIcon.Error);
                read.Close();
               
                return;
            }
            read.Close();
           
            ds.Tables["ScheduleInfo"].Clear();
            db.OpenConnection();
            string st2 = "select count,teamName as hostTeamId,name as awayTeamId,competitionTime,competitionPosition,score,entryPerson,entryTime from ScheduleInfo  inner join TeamInfo on TeamInfo.id=ScheduleInfo.hostTeamId " +
             "inner join ad on ad.id=ScheduleInfo.awayTeamId  where teamName like '" + textBox1.Text + "%'";
            adapter = new SqlDataAdapter(st2, db.Connection);
            adapter.Fill(ds, "ScheduleInfo");
            this.dataGridView1.DataSource = ds.Tables["ScheduleInfo"];
         
        }
    }
}
